package ua.com.hackaton.core;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: Eugene Borshch
 * Date: 6/26/11
 * Time: 6:01 AM
 * To change this template use File | Settings | File Templates.
 */
public class MyData implements Parcelable
{
    Map<String, Integer> data_map = new HashMap<String, Integer>();

    public MyData() {
    }

     public MyData(Map<String, Integer> data_map) {
         this.data_map  = data_map;
    }

    public Map<String, Integer> getData_map()
    {
        return data_map;
    }

    public void setData_map(Map<String, Integer> data_map)
    {
        this.data_map = data_map;
    }

    public int describeContents() {
        return 0;
    }

    public void writeToParcel(Parcel dest, int parcelableFlags) {
        final int N = data_map.size();
        dest.writeInt(N);
        if (N > 0) {
            for (Map.Entry<String, Integer> entry : data_map.entrySet()) {
                dest.writeString(entry.getKey());
                Integer dat = entry.getValue();
                dest.writeInt(dat);
                // etc...
            }
        }
    }

    public static final Creator<MyData> CREATOR = new Creator<MyData>() {
        public MyData createFromParcel(Parcel source) {
            return new MyData(source);
        }
        public MyData[] newArray(int size) {
            return new MyData[size];
        }
    };

    private MyData(Parcel source) {
        final int N = source.readInt();
        for (int i=0; i<N; i++) {
            String key = source.readString();

           Integer dat = source.readInt();
            // etc...
            data_map.put(key, dat);
        }
    }
}
